package com.jilefojing.util;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropertyConfig {

	private static Logger logger = LoggerFactory.getLogger(PropertyConfig.class);

	private static ResourceBundle rb = null;

	static {
		try {
			if (null == rb) {
				rb = ResourceBundle.getBundle("/properties/commons_config");
			}
		} catch (Exception e) {
			logger.info("reading property_config error! ");
			e.printStackTrace();
		}
	}

	public static String getPropertyValue(String key) {
		String value = rb.getString(key);
		// try {
		// value = new String(value.getBytes("ISO8859-1"), "utf-8");
		// } catch (UnsupportedEncodingException e) {
		// e.printStackTrace();
		// }
		return value;
	}

	public static Map<String, String> getValueArrBySplit(String key, String splitStr) {
		Map<String, String> map = new HashMap<String, String>();
		String keyWord = PropertyConfig.getPropertyValue(key);
		if (Detect.notEmpty(keyWord)) {
			String[] keys = keyWord.split(splitStr);
			for (int i = 0; keys != null && i < keys.length; i++) {
				map.put(keys[i], keys[i]);
			}
		}
		return map;
	}

}
